#ifndef xpack_test_algo_distinct
#define xpack_test_algo_distinct
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::test_algo_distinct::inc
#include"test/helper.hpp" // 需要放第一
#include"algo/distinct.hpp"
#include"interface/seqptr.hpp"
#include"math/random.hpp"
#include"utils/memory.hpp"
#include"utils/array.hpp"
#include"utils/bits_indicator.hpp"
#pragma pop_macro("xuser")

namespace mixc::test_algo_distinct{
    xtest("distinct") {
        using namespace inc;
        
        static array<u32, 64> r;
        uxx used = inc::memory::used_bytes();

        for(uxx i = 1; i < r->length; i++){
            for(uxx j = 0; j < r->length; j++){
                auto && bmp = bits_indicator<1024>{};
                auto    seq = seqptr<u32>(r).subseq(co{0, j});

                for(uxx k = 0; k < seq->length; k++){
                    seq[k] = random<u32>() % i;
                    bmp.set(seq[k]);
                }

                auto new_list = inc::distinct(seq, [](uxx len) -> decltype(seq){
                    static u32 buffer[1024];
                    return { buffer, len };
                });

                for(uxx k = 0; k < new_list->length; k++){
                    auto exist = bmp.get(new_list[k]);
                    xassert(exist, i, j, k, new_list[k]);
                    bmp.reset(new_list[k]);
                }
            }
        }

        xassert_eq(used, inc::memory::used_bytes());
    };
}

#endif
